﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenSoftStore.BusinessLogic.Bill;
using OpenSoftStore.BusinessLogic.Member;
using OpenSoftStore.Client.Common;

namespace OpenSoftStore.Client.UIL.ManageReport
{
    public partial class ReportMemberProductSale : UserControl
    {
        private MemberLogic LgcMember;
        private static ReportMemberProductSale instance;
        public static ReportMemberProductSale Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new ReportMemberProductSale();
                }
                return instance;
            }
        }

        public ReportMemberProductSale()
        {
            InitializeComponent();
            LgcMember = new MemberLogic();

            dgvProduct.AutoGenerateColumns = false;
            dgvProductGroup.AutoGenerateColumns = false;
            btnSearch_Click(null, null);
            SPACommon.SetDataGridStyle(dgvProductGroup);
            SPACommon.ShowSummary(dgvProductGroup);
            SPACommon.SetDataGridStyle(dgvProduct);
            SPACommon.ShowSummary(dgvProduct);
        }


        private void dgvProductGroup_SelectionChanged(object sender, EventArgs e)
        {
            DateTime from = dtpFrom.Value.Date;
            DateTime to = dtpTo.Value.Date.AddDays(1).AddSeconds(-1.0);
            if (dgvProductGroup.CurrentRow==null) return;
            var productId = dgvProductGroup.CurrentRow.Cells["ProductId"].Value.ToString();
            var memberId = dgvProductGroup.CurrentRow.Cells["MemberId"].Value.ToString();
            dgvProduct.AutoGenerateColumns = false;
            dgvProduct.DataSource = LgcMember.GetMemberProductSaleItemDataTable(from, to, productId, memberId);

        }

        private void btnOutput_Click(object sender, EventArgs e)
        {
            SPACommon.ExportToExcel(dgvProductGroup, "客户消费喜好统计");
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            DateTime from = dtpFrom.Value.Date;
            DateTime to = dtpTo.Value.Date.AddDays(1).AddSeconds(-1.0);
            dgvProductGroup.AutoGenerateColumns = false;
            dgvProductGroup.DataSource = LgcMember.GetMemberProductSaleDataTable(from, to);
        }

        private void dgvProductGroup_SizeChanged(object sender, EventArgs e)
        {

        }
    }
}
